const TimeShow = (date) => {
  // 现在时间
  const nowDate = new Date()
  const nowYear = nowDate.getFullYear()
  const nowMonth = nowDate.getMonth() + 1
  const nowDay = nowDate.getDate()
  const nowHours = nowDate.getHours()
  const nowMinutes = nowDate.getMinutes()

  let getTime = ''

  const dates = date.split('-')
  const Year = Number(dates[0])
  const Month = Number(dates[1])
  const tt = dates[2].split(' ')
  const tt2 = tt[1].split(':')
  const day = Number(tt[0])
  const hourse = Number(tt2[0])
  const minuts = Number(tt2[1])

  if(nowYear !== Year) {
    getTime = date
  } else {
    if((nowMonth !== Month) || ((nowDay - day) > 7)) {
      getTime = `${Month}-${dates[2]}`
    } else {
      if((nowDay - day) <= 7 && (nowDay !== day)) {
        if(((nowDay - day) <= 1) && (nowHours < hourse)) {
          getTime = `${(nowHours + 24) - hourse}小时前`
        } else {
          getTime = `${nowDay - day}天前`
        }
      } else {
        if(nowHours !== hourse) {
          if(((nowHours - hourse) <= 1) && nowMinutes < minuts) {
            getTime = `${(nowMinutes + 60) - minuts}分钟前`
          } else {
            getTime = `${nowHours - hourse}小时前`
          }
        } else {
          if(nowMinutes !== minuts) {
            getTime = `${nowMinutes - minuts}分钟前`
          } else {
            getTime = '刚刚'
          }
        }
      }
    }
  }
  return getTime
}

export default TimeShow
